package managerSIP;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import net.sf.asterisk.manager.ManagerConnection;
import net.sf.asterisk.manager.ManagerConnectionFactory;

public class AsteriskConnector 
{
    /**
	 * @uml.property  name="managerConnection"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private ManagerConnection managerConnection;
    
	public AsteriskConnector() 
	{
		// Access file
		File file = new File("asterisk.properties");    
		Properties props = new Properties();
		FileInputStream fis = null;
		try 
		{
		    fis = new FileInputStream(file);
		    //Read properties in file mysql.properties
		    props.load(fis); 
		    fis.close();
		}
		catch (IOException ex) {
		    System.out.println(ex.getMessage());
		    ex.printStackTrace();
		}
		
		// connect to Asterisk
		try {
			String userName = props.getProperty("asterisk.username");
	        String password = props.getProperty("asterisk.password");
	        String server = props.getProperty("asterisk.server");
			ManagerConnectionFactory factory = new ManagerConnectionFactory();
			this.managerConnection = factory.getManagerConnection(server,userName,password);
		}
		catch(IOException ie) {
			System.out.println(ie.toString());
		}
		catch(Exception e) {
			System.out.println(e.toString());
		}
	}

}